#ifndef _FEITIAN_RSA_H_
#define _FEITIAN_RSA_H_
#ifdef __cplusplus
extern "C"
{
#endif

typedef struct {
  unsigned int  bits;                   // length in bits of modulus
  unsigned char modulus[128];           // modulus
  unsigned char exponent[128];          // public exponent
} R_RSA_PUBLIC_KEY;

typedef struct {
  unsigned int  bits;                   // length in bits of modulus
  unsigned char modulus[128];           // modulus
  unsigned char publicExponent[128];    // public exponent
  unsigned char exponent[128];          // private exponent
  unsigned char prime[2][64];           // prime factors
  unsigned char primeExponent[2][64];   // exponents for CRT
  unsigned char coefficient[64];        // CRT coefficient
} R_RSA_PRIVATE_KEY;

int RSAPublicBlock (unsigned char *output,int *outputLen,unsigned char *input,int inputLen,R_RSA_PUBLIC_KEY *publicKey);
int RSAPrivateBlock (unsigned char *, int *, unsigned char *, int, R_RSA_PRIVATE_KEY *);

int RSAPublicEncrypt  (unsigned char *, int *, unsigned char *, int, R_RSA_PUBLIC_KEY  *); 
int RSAPrivateEncrypt (unsigned char *, int *, unsigned char *, int, R_RSA_PRIVATE_KEY *);

int RSAPublicDecrypt(unsigned char *, int *, unsigned char *, int,  R_RSA_PUBLIC_KEY *);
int RSAPrivateDecrypt(unsigned char *, int *, unsigned char *, int, R_RSA_PRIVATE_KEY *);
#ifdef __cplusplus
}
#endif
#endif
